package com.sfx.concurrent.demo.concurrent.FixedRunOrder;

import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-09
 * Time: 19:09
 */
@Slf4j(topic = "c.WaitNotify")
public class WaitNotify {
    private static Object lock = new Object();
    private static boolean t2Running = false;
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (lock) {
                while(!t2Running) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                log.debug("1");
            }
        },"t1").start();
        new Thread(()->{
            synchronized (lock) {
                log.debug("2");
                t2Running = true;
                lock.notify();
            }
        },"t2").start();
    }
}
